#include "stackdlg.h"
#include <QHBoxLayout> //水平布局
#include <QVBoxLayout>  //垂直布局

StackDlg::StackDlg(QWidget *parent)
    : QDialog(parent)
{
    setWindowIconText(tr("StackedWidget"));
    list = new QListWidget(this); //新建QlistWidget控件对象
    //插入三个对象
    list -> insertItem(0,tr("Window1"));
    list -> insertItem(1,tr("Window2"));
    list -> insertItem(2,tr("Window3"));
    //创建三个QLabel标签控件对象，显示三层窗体
    label1 = new QLabel(tr("WindowTest1"));
    label2 = new QLabel(tr("WindowTest2"));
    label3 = new QLabel(tr("WindowTest3"));
    stack = new QStackedWidget(this);
    //创建QStackedWidget堆栈窗体对象
    //将QLable标签插入堆栈窗体
    stack ->addWidget(label1);
    stack ->addWidget(label2);
    stack ->addWidget(label3);

    QHBoxLayout *mainLayout = new QHBoxLayout(this);
    //QVBoxLayout *mainLayout = new QVBoxLayout(this);
    //对整个对话框进行布局
    mainLayout -> setMargin(5); //边距5
    mainLayout ->setSpacing(5);  //控件间距为5
    mainLayout ->addWidget(list);
    mainLayout ->addWidget(stack,0,Qt::AlignHCenter);
    mainLayout ->setStretchFactor(list,1); //设定可伸缩控件，第一个参数指定控件，第二个大于0表示可以伸缩
    mainLayout ->setStretchFactor(stack,3);
    connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int)));
}

StackDlg::~StackDlg()
{

}
